package com.teach.servlet.admin;

import com.teach.dao.AdminInfoDAO;
import com.teach.dao.MedalInfoDAO;
import com.teach.dao.impl.AdminInfoDAOImpl;
import com.teach.dao.impl.MedalInfoDAOImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/medal-delete.let")
public class MedalDeleteServlet extends HttpServlet {
    private MedalInfoDAO dao = new MedalInfoDAOImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.reset();
        response.setContentType("application/json;charset=UTF-8");
        try {

            String medalId = request.getParameter("medalId");

            try {
                dao.deleteById(medalId);
                response.getWriter().print("{\"ok\":true}");
            } catch (Exception ex) {
                throw new ServletException("删除失败", ex);
            }

        }catch (Exception ex){
            response.getWriter().print("{\"ok\":false,\"msg\":\""+ex.getMessage()+"\"}");
        }

        response.flushBuffer();
    }
}
